`rwmGetColours` <-
function(colourPalette, numColours)
{
   ##If colourPalette is length one, use it to get a vector of colours
   if(length(colourPalette)==1){
          validOptions<-c("heat","topo","palette")
          gotRColorBrewer<-"RColorBrewer" %in% .packages(TRUE)
          if(gotRColorBrewer){
          RColorBrewerColours<-rownames(RColorBrewer::brewer.pal.info)
          validOptions<-c(validOptions,RColorBrewerColours)
          }

          if(!colourPalette %in% validOptions){
           colourPalette=="heat"
           warning("specified colourPalette was invalid, using 'heat'")
          }
          if(colourPalette=="heat")
        	{
        		colourPalette<-rev(heat.colors(numColours))
        	} else

          if(colourPalette=="topo")
        	{
        		colourPalette<-topo.colors(numColours)
        	} else
        	if(gotRColorBrewer && colourPalette %in% RColorBrewerColours){
        	   require(RColorBrewer)
        	   maxColoursAllowed<-brewer.pal.info[colourPalette,"maxcolors"]
        	   if(numColours<maxColoursAllowed && numColours>3){
        	   colourPalette<-brewer.pal(numColours,colourPalette)
        	   }else{
        	   colourPalette<-brewer.pal(maxColoursAllowed,colourPalette)
        	   }

        	}
	  if(colourPalette=="palette")
		{
			colourPalette<-palette()
		}
   }
   ##If the number of colours is not enough, use interpolation.
   if(length(colourPalette)!=numColours){
    colourPalette<-colorRampPalette(colourPalette)(numColours)
   }
   return(colourPalette)

}
